package com.project.forlearning.controller;

import com.project.forlearning.service.BackUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户处理API
 */
@Api(value = "UserController",tags = ("后台关于用户的API"))
@RestController
@RequestMapping("/users")
@CrossOrigin
public class BackUserController {

    @Autowired
    private BackUserService adminService;

    @ApiOperation("查询单个用户,需传入userId")
    @GetMapping("{userId}")
    public String getUser(@ApiParam(value = "用户编号", required = true) @PathVariable Integer userId){
        return adminService.findUser(userId);
    }

    @ApiOperation("查询全部用户")
    @GetMapping()
    public String getAllUser(){
        return adminService.findAllUser();
    }

    @ApiOperation("删除用户，需传入userId")
    @DeleteMapping("{userId}")
    public String deleteUser(@ApiParam(value = "用户编号", required = true) @PathVariable Integer userId){
        return adminService.deleteUser(userId);
    }
}
